package com.edou.study.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/hello")
public class ChatHelloController {

    @Resource  // 对话模型，调用阿里云百炼平台
    private ChatModel chatModel;

    /**
     * 通用调用
     * @param msg
     * @return
     */
    @GetMapping("/dochat")
    public String doChat(@RequestParam(name = "msg",defaultValue = "你是谁") String msg) {
        String result = chatModel.call(msg);
        return result;
    }

    /**
     * 流式返回调用
     */
    @GetMapping("/streamchat")
    public Flux<String> streamChat(@RequestParam(name = "msg", defaultValue = "你是谁") String msg) {
        return chatModel.stream(msg);
    }
}
